package com.qhg.saas_server.controller;

import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.Warehouse;
import com.qhg.saas_server.pojo.dto.WarehouseInfoDto;
import com.qhg.saas_server.service.impl.WarehouseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/Warehouse")
public class WarehouseController {

    @Autowired
    WarehouseServiceImpl warehouseService;

    /*通过仓库名和负责人员分页模糊查询仓库*/
    @PostMapping("/SelectWarehouse")
    public Result SelectWarehouse(Integer pageNum, Integer pageSize, String wareName, String wareComploName){
        PageInfo pageInfo = warehouseService.SelectWarehouse(pageNum, pageSize, wareName, wareComploName);
        return Result.success(pageInfo);
    }
    /*通过ID查询仓库的信息*/
    @GetMapping("/SelectById")
    public Result SelectById(Integer wareId){
        WarehouseInfoDto warehouseInfoDto = warehouseService.SelectById(wareId);
        return Result.success(warehouseInfoDto);
    }
    /*插入仓库信息*/
    @PostMapping("/InsertWarehouse")
    public Result InsertWarehouse(@RequestBody Warehouse warehouse){
        warehouseService.InsertWarehouse(warehouse);
        return Result.buildSuccess();
    }
    /*修改仓库状态*/
    @PostMapping("/UpdateStatus")
    public Result UpdateStatus(Integer wareStatus,Integer wareId){
        warehouseService.UpdateStatus(wareStatus,wareId);
        return Result.buildSuccess();
    }
    /*修改仓库的信息*/
    @PostMapping("/UpdateWarehouse")
    public Result UpdateWarehouse(@RequestBody Warehouse warehouse){
        System.out.println(warehouse);
        warehouseService.UpdateWarehouse(warehouse);
        return Result.buildSuccess();
    }
    /*通过Id删除仓库*/
    @GetMapping("/DeleteById")
    public Result DeleteById(Integer wareId){
        warehouseService.DeleteById(wareId);
        return Result.buildSuccess();
    }
}
